In a follow-up patch we will want to either reserve or allocate a port
for various event channel helpers.
A new wrapper is introduced to either reserve a given port or allocate
a fresh one if zero.
Take the opportunity to replace the open-coded version in
evtchn_bind_virq().
Signed-off-by: Stanislav Kinsburskii <staskins@amazon.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xsm_evtchn_close_post(chn);
}
+static int evtchn_get_port(struct domain *d, evtchn_port_t port)
+{
+ int rc;
+
+ if ( port != 0 )
+ rc = evtchn_allocate_port(d, port);
+ else
+ rc = get_free_port(d);
+
+ return rc ?: port;
+}
+
int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
{
struct evtchn *chn;
if ( read_atomic(&v->virq_to_evtchn[virq]) )
ERROR_EXIT(-EEXIST);
- if ( port != 0 )
- {
- if ( (rc = evtchn_allocate_port(d, port)) != 0 )
- ERROR_EXIT(rc);
- }
- else
- {
- int alloc_port = get_free_port(d);
-
- if ( alloc_port < 0 )
- ERROR_EXIT(alloc_port);
- port = alloc_port;
- }
+ port = rc = evtchn_get_port(d, port);
+ if ( rc < 0 )
+ ERROR_EXIT(rc);
+ rc = 0;
chn = evtchn_from_port(d, port);